Page({
    data: {
        xPageReady: true ,
        page_num:1,
        xArticle:[],
        warning:false,
        loading:false,
        navcurrent:0,
        id:''
    },
    onLoad: function (options) {
        this.xInit()
    },
    onReachBottom:function(){
      let that =this
      that.setData({
        page_num: that.data.page_num + 1,
        warning: false
      })
      that.getList(that.data.id)
    },
    xInit:  function () {
        let that = this
        wx.cloud.callFunction({
          name: 'pain_class',
          data: {
            action: "get_classification"
          }
        }).then(res => {
          that.setData({
            navList:res.result
          })
          if(res.result.length>0){
            that.setData({
              id:res.result[0]._id
            })
            that.getList(res.result[0]._id)
          }else{
            that.getList('')
          }
        })
    },
    getList:function(id){
      let that =this
      wx.cloud.callFunction({
        name: 'article',
        data: {
          action: "get_article_list",
          dataObj: {
              page_num: that.data.page_num,
              limit_num: 10,
              classification_id:id
          }
        }
    }).then(res => {
        let act = res.result
        if(res.result.length==0){
          that.setData({
            loading: false,
            warning: true
          })
          setTimeout(() => {
            that.setData({
              warning: true
            })
          }, 2000)
        }
        for(var i in res.result){
          that.data.xArticle.push(res.result[i])
        }
        that.setData({
          xArticle : that.data.xArticle,
          xPageReady : false
        })
      })
    },
    xTabChange: function (e) {
        let that = this
        let params = e.currentTarget.dataset
        that.setData({
          id:params.id,
          xArticle:[],
          page_num:1,
          navcurrent:params.index
        })
        that.getList(that.data.id)
    },

    xToArticleDetail: function (e) {
        let id = e.currentTarget.dataset.id
        wx.navigateTo({
            url: '/subtool/pages/article/detail/index?id=' + id,
        })
    },
})